home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / fortran.zip / SBM.LS2 < prev    next >
Text File  |  1991-01-10  |  22KB  |  621 lines

  1.  
  2.  
  3.                                   CONTENTS
  4.  
  5.     Introduction to SBM fortran. . . . . . . . . . . . . . . . . . . . iii
  6.     Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
  7.     Current status . . . . . . . . . . . . . . . . . . . . . . . . . . v
  8.  
  9.     Fortran statements . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  10.     Statement lables . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  11.     Symbolic names and keywords  . . . . . . . . . . . . . . . . . . . 1-1
  12.     Statement order  . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  13.  
  14.     Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
  15.     Include  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
  16.  
  17.     Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
  18.              Byte, Character, Integer*1, Logical . . . . . . . . . . . 1-3
  19.              Word, Integer, Integer*2  . . . . . . . . . . . . . . . . 1-3
  20.              Doubleword, Integer*4 . . . . . . . . . . . . . . . . . . 1-3
  21.              Character strings, ASCIIZ . . . . . . . . . . . . . . . . 1-3
  22.  
  23.     Quoted strings . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
  24.     Data declaration and initialization  . . . . . . . . . . . . . . . 1-5
  25.     Data statement . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
  26.  
  27.     OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  28.              UNIT (5-255). . . . . . . . . . . . . . . . . . . . . . . 2-1
  29.              IOCB names  . . . . . . . . . . . . . . . . . . . . . . . 2-1
  30.              FILE  . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  31.              ALIAS (alternate name for io unit). . . . . . . . . . . . 2-1
  32.              STATUS (old, new, append) . . . . . . . . . . . . . . . . 2-1
  33.              RECL  . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  34.  
  35.     READ STATEMENTS  . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
  36.            Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-3
  37.            formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
  38.            List directed . . . . . . . . . . . . . . . . . . . . . . . 2-4
  39.  
  40.            Next character from keyboard (NEXCHAR). . . . . . . . . . . 2-4
  41.  
  42.     WRITE STATEMENTS . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  43.            Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  44.            formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  45.            List directed . . . . . . . . . . . . . . . . . . . . . . . 2-6
  46.  
  47.            SHOW_CHAR (display a character on screen) . . . . . . . . . 2-6
  48.            CRLF  (write cr,lf to specified IOCB) . . . . . . . . . . . 2-6
  49.  
  50.     FORMAT STATEMENTS  . . . . . . . . . . . . . . . . . . . . . . . . 2-7
  51.            Field and edit descriptors. . . . . . . . . . . . . . . . . 2-7
  52.  
  53.     ARITHMETIC EXPRESSIONS . . . . . . . . . . . . . . . . . . . . . . 3-1
  54.            INC, DEC  (incrementing and decrementing variables. . . . . 3-1
  55.            ADD, SUB  (adding to, or subtracting from variables . . . . 3-1
  56.            Subscripts  . . . . . . . . . . . . . . . . . . . . . . . . 3-2
  57.  
  58.  
  59.  
  60.                      INTRODUCTION TO SBM FORTRAN
  61.  
  62.     This manual describes  SBM FORTRAN.  SBM is based on American National
  63.     Standards Institute FORTRAN 77 language.  It is assumed that the reader
  64.     has knowledge of an existing FORTRAN language and is familiar with MSDOS
  65.     or PCDOS operating system.  This manual is not intended to teach
  66.     FORTRAN, but is intended to be used as reference material only.
  67.  
  68.     The original intention of SBM fortran was the author's answer to the 'C'
  69.     language. The cryptic nature of 'C', while appealing to many
  70.     programmers, leaves me cold. While I fully appreciate the power of the
  71.     'C' language (as with assembler), I felt that there was needed something
  72.     that would better suit my style.
  73.  
  74.     I also remember when I brought my first XT home. There were many
  75.     fortran-written utilities that I had on the Z-80 without which I felt
  76.     very helpless. By the time I had rounded up the money to buy the system,
  77.     I had none left for the software that I very sorely needed.  An
  78.     affordable compiler of an easily learned language seemed to the the
  79.     answer.  A good reason  for someone, such as I, to write SBM fortran.
  80.  
  81.     The powerful fortran systems that are now on the market are designed with
  82.     the high-level user in mind.  Program size is not important.  I needed
  83.     something that would generate about the same code as if I wrote the it in
  84.     assembler.
  85.  
  86.     This compiler operates by converting FORTRAN source code into assembler
  87.     instructions,  which are then converted into machine code using WASM, an
  88.     assembler written by ERIC TAUK, of Merengo, IL.  The result is a COM
  89.     file, which can then be run on any MSDOS based system.
  90.  
  91.     THIS IS VERSION 1.00. To most of us this means a system that works well
  92.     enough for the author, but sometimes awkward for the user. Here is a
  93.     problem. I am in the process of moving to Wyoming.  Here in Denver, I
  94.     have access to many excellent bulletin boards. In Wyoming, that will
  95.     not be the case. I must therefore release this version knowing that
  96.     there may be bugs.  Since I will no longer have easy access to the
  97.     boards, I will not longer have easy access to you, the user. I must
  98.     therefore go to a 'shareware' mode.
  99.  
  100.     To provide this connection, You must send me your name and mailing
  101.     address. That will make you a registered user. To receive ANY updates of
  102.     this compiler, you MUST be a registered user. At a minimum, I will
  103.     upgrade to provide some of the functions that I need. Registered users
  104.     will receive the first (or most recent) update. I most certainly need
  105.     your suggestions for improvements and bug removal. If you like this
  106.     compiler as I believe you will, your $20 contribution will be
  107.     appreciated.  Since I will no longer have access to the boards, that's
  108.     the only way that you can receive the update.
  109.  
  110.  
  111.  
  112.     MSDOS is a registered trademark of Microsoft Corporation.
  113.     PCDOS is a registered trademark of IBM Corporation.
  114.  
  115.  
  116.  
  117.  
  118.  
  119.                                    iii
  120.  
  121.  
  122.  
  123.     CURRENT STATUS OF SBM FORTRAN
  124.  
  125.     BE VERY CAUTIOUS USING ANY SORTWARE!  Do not trust it!  Even if you
  126.     have been using it for awhile, mentally EDIT the output.  Does it look
  127.     reasonable?  You are the best judge.
  128.  
  129.     SBM fortran is not a  scientific compiler. i.e., it does not have
  130.     floating point.
  131.  
  132.     Integer*4 is there, but needs more hooks before it can be used.
  133.  
  134.     Arithmetic expressions are primitive, but gramatically correct and
  135.     transportable.  This feature will be upgraded to some extent.
  136.  
  137.     Needs more diagnostic messages.  SBM fortran is not just forgiving. It's
  138.     actually permissive.
  139.  
  140.     But, on the other hand, if you accept the above limitations, and write a
  141.     program using standard fortran coding techniques, it will work, and the
  142.     code can be put up and run under most other F77 compilers, without
  143.     modification.
  144.  
  145.  
  146.  
  147.  
  148.     FUTURE OF SBM FORTRAN
  149.  
  150.     SBM fortran was not, and is not intended to be a full-blown fortran
  151.     compiler. It is not intended to compete with the more powerful
  152.     systems.
  153.  
  154.     Integer*4 is one feature that will certainly be implememted. With large
  155.     integers, you can do quite a lot.  Accounting work and other related
  156.     types of work require precise calculations. Large integers makes that
  157.     precision possible. Instead of dollars and cents, you can carry
  158.     everything in total cents. i.e. $156.25 is 15625 cents. For output,
  159.     the format statement can direct that a decimal point be inserted (this
  160.     feature is already installed, but not yet usable).
  161.  
  162.     The compiler needs compile time and runtime error detection that it does
  163.     not now have. Some errors simply lock up the system.  That is something
  164.     that must be addressed in the first update.
  165.  
  166.     The direction of its future is mostly up to you.  I have some floating-
  167.     point routines that could be implemented, but I will probably not work in
  168.     that direction unless there's enough response.  The routines are in
  169.     another  fortran compiler of mine which I chose not to release at this
  170.     time.
  171.  
  172.  
  173.     There's  another feature, TONTO (trace-on, trace_off), that might also be
  174.     moved  from my other compiler.
  175.  
  176.                                     v
  177.  
  178.     1-2
  179.  
  180.     COMMENTS - You can use a semi-colon(;), an asterisk(*) or hyphen (-) in
  181.     column 1 to specify that the line is a comment. In addition, if you place
  182.     a ';' anywhere in the statement portion of a source line, the rest of
  183.     that statement will be treated as a comment. A blank line is also
  184.     considered to be a comment.
  185.  
  186.     Individual assembler code statements can be inserted anywhere by placing
  187.     a plus (+) in column 1.
  188.  
  189.  
  190.     INCLUDE
  191.  
  192.     Blocks of fortran statements, assembler code, and macros may be inserted
  193.     using the INCLUDE option.
  194.  
  195.     Syntax:    INCLUDE pathname   Pathname can name any file that is
  196.                                   currently on line, on any disk.
  197.  
  198.     To include assembler code or macros, the statement must have a '+' in
  199.     column 1 and the pathname must be in quotes.
  200.  
  201.     Example:  +   include 'maclib.asm'
  202.  
  203.  
  204.     A small macro library is provided to generate some of the code that the
  205.     compiler needs.  You may build one of your own choosing and insert it
  206.     using the + INCLUDE option.
  207.  
  208.  
  209.     1-4
  210.  
  211.     QUOTED STRINGS
  212.  
  213.     Over the years, we programmers have created a standard that would not be
  214.     acceptable to people other than programmers. That is, calling an
  215.     apostrophy a quote! When we think of quoted strings, we think of an ascii
  216.     string enclosed in apostrophies, not quotes. Don't know how this started,
  217.     but we all do it. Anyway, format statements sometimes require us to
  218.     specify a 'quoted' string for output. With this in mind, in this manual,
  219.     when we talk of a quoted string, we mean a string that is enclosed in
  220.     apostrophies.
  221.  
  222.     When entering a quoted string that we wish wish to contain an imbedded
  223.     quote, SBM FORTRAN requires that you use an ACTUAL quote(").  Standard
  224.     fortran wants you to use two apostrophies in a row.  We do it differently
  225.     here.
  226.  
  227.  
  228.  
  229.     example:  standard fortran requires:
  230.  
  231.               FORMAT('We sometimes don''t follow standards')
  232.  
  233.  
  234.  
  235.     We do it this way:
  236.  
  237.               FORMAT('We sometimes don"t follow standards')
  238.  
  239.  
  240.  
  241.  
  242.  
  243.     2-2
  244.  
  245.     READ STATEMENTS
  246.  
  247.     READ statements transfer data from a specified I/O unit to memory.  You
  248.     can reference both external and internal files.  The input data may be
  249.     any ASCII stream.
  250.  
  251.     Syntax:   READ(UNIT [,FMAT]) list
  252.  
  253.  
  254.     UNIT is one of:
  255.  
  256.         (1) An integer constant in the range of 5 to 255 that identifies an
  257.             external unit previously referenced in an OPEN statement.
  258.  
  259.         (2) An asterisk (*) specifying the default I/O unit (console).
  260.             May be redirected.
  261.  
  262.         (3) The name of an internal array (such as the input buffer)
  263.             containing data. This is the manner by which you can re-read
  264.             a data record.  explanation:  on any read, the data is read into
  265.             the input buffer as raw data.  If a format has been specified,
  266.             the record is transformed into the corresponding input fields.
  267.             But: even after formatting, the raw data is still in the input
  268.             buffer.
  269.  
  270.     FMAT is a parameter that specifies whether explicit or list-directed
  271.             formatting is to be applied. It may take either of the following
  272.             forms.
  273.  
  274.          (1) A statement label of a format statement. The statement label
  275.              must begin with a numeric character 0-9. The rest of the label
  276.              can be anything of your own choosing.
  277.  
  278.          (2) '*' that specifies list-directed formatting.
  279.  
  280.  
  281.     If FMAT is omitted, a 'null' read is performed, effectively passing over
  282.     an input record.  The unformatted contents of the record are not lost,
  283.     however, but are preserved in the input-output control buffer (IOCB).
  284.     The string is available by its IOCB name, and may be treated as any
  285.     other character array.
  286.  
  287.  
  288.     LIST names the variables, arrays, array elements and character strings
  289.     to which data will be transferred.
  290.  
  291.     If end of file is sensed, the logical variable 'EOF' is set to TRUE.
  292.  
  293.     2-4
  294.  
  295.     FORMATTED READ
  296.  
  297.     Syntax:   READ(UNIT,FMAT]) list
  298.  
  299.     This is a two-step operation.
  300.  
  301.     Step 1 reads the record into the IOCB (an unformatted read).
  302.  
  303.     Step 2 applies the formatting and transforms the ascii data into the
  304.     various input fields.
  305.  
  306.  
  307.  
  308.  
  309.     LIST-DIRECTED READ
  310.  
  311.     Syntax:   READ(UNIT,*) list
  312.  
  313.     Read statements are either unformatted or formatted. The difference in a
  314.     list-directed read is that the compiler is going to create a format for
  315.     itself, based on what kind of data we have in the 'list'.
  316.  
  317.     This is a two-step operation.
  318.  
  319.     Step 1 reads the record into the IOCB (an unformatted read).
  320.  
  321.     Step two applies the compiler-designed formatting and transforms the
  322.     ascii data into the various input fields.
  323.  
  324.  
  325.  
  326.  
  327.     NEXCHAR
  328.  
  329.     Reads a character from the keyboard.  Does not echo to the console. If
  330.     no character is ready, waits for operator to enter one.  The character
  331.     is available to the program in register AL.  Execution resumes.
  332.  
  333.     See 'testall.for' for a practical example. (NEXCHAR and WAIT are same)
  334.  
  335.     2-6
  336.  
  337.     LIST-DIRECTED WRITE
  338.  
  339.     Syntax:   WRITE(UNIT,*) list
  340.  
  341.     In a list-directed write, a format is constructed by the compiler based
  342.     upon the data type of the various fields. Other than that, it is exactly
  343.     like the formatted write.
  344.  
  345.     While most compilers require that the first character of an output record
  346.     be used for carriage control, SBM fortran does not. When output is to be
  347.     directed to a printer, feel free to insert ascii control codes, 0Ch for
  348.     eject, 0Dh for double space.
  349.  
  350.  
  351.  
  352.  
  353.     SHOW_CHAR
  354.  
  355.     Display the character that is in the AL register.  You can use this
  356.     statement immediately after NEXCHAR.
  357.  
  358.  
  359.  
  360.  
  361.     SHOW_CHAR  'char'
  362.  
  363.     Display specific character.  The character can be a printable
  364.     character enclosed in quotes, or a hex constant.
  365.     Example:    show_char 8   gives us a back-space on the console.
  366.  
  367.  
  368.  
  369.     3-2
  370.  
  371.     SUBSCRIPTING
  372.  
  373.  
  374.     Any variable may be accessed by using the variable name in a fortran
  375.     statement. To access variables in positions other than the first, you
  376.     must (1) use an integer offset or (2) use a subscript.
  377.  
  378.     An integer offset may be used by simply appending the variable name with
  379.     a plus-or-minus constant. Example: 'ARRAY+4' points to the fifth
  380.     position of a integer*1 or character array. If the array was integer*2,
  381.     it would point to the third position, since each element in an integer*2
  382.     array requires two positions. While this is not a standard fortran
  383.     method of accessing data, it is by far the most efficient.
  384.  
  385.     Subscripts, on the other hand, indicate the position of an element by
  386.     enclosing a subscript expression within a pair of parentheses.
  387.  
  388.     The subscript expression can be an integer constant, and integer
  389.     variable, or an integer variable plus-or-minus an integer constant.
  390.  
  391.       Examples: array(k), date(m+2), etc..
  392.  
  393.     Other informative examples can be found in the program 'TESTALL.FOR'.
  394.  
  395.  
  396.     A word of caution: Do not allow the expression to go negative. You will
  397.     access something, but who knows what...
  398.  
  399.     4-2
  400.  
  401.                             CONTROL STATEMEMTS
  402.  
  403.  
  404.     CMP variable, constant
  405.  
  406.     Compare a variable to a known value. This statement is identical to it's
  407.     ASM equivalent. Subscripts are not permitted, but offsets can be used.
  408.  
  409.     Usage:  CMP  Name, 'A'
  410.             CMP  Name+2,'B'
  411.             CMP  Year, 99
  412.  
  413.     This statement essentially subtracts the constant from the variable, does
  414.     not change any values in memory but, sets the control flags. You must
  415.     then use a conditional jump for program control.
  416.  
  417.  
  418.  
  419.  
  420.  
  421.     COMPARE
  422.  
  423.     Compare a string of characters against a model. Not case sensitive,
  424.     'TOKEN' should be upper case.
  425.  
  426.     Usage:  COMPARE KEWORD, 'TOKEN'
  427.  
  428.  
  429.     Example, from the compiler.
  430.  
  431.     -   see if prefix 'byte' or 'word'
  432.         compare keword,'BYTE'    ;
  433.         if(eq) goto destin_ok    ; if 'byte' or 'word',
  434.         compare keword,'WORD'    ; accept it as-is.
  435.         if(eq) goto destin_ok    ;
  436.  
  437.  
  438.     GOTO          Unconditional transfer of control.
  439.     JMP           Same as GOTO
  440.  
  441.  
  442.  
  443.     WAIT
  444.  
  445.     Wait for operator. Program execution stops. When operator has pressed
  446.     any key, execution resumes.
  447.  
  448.  
  449.  
  450.     PAUSE ['message']
  451.  
  452.     Stops, waits for operator. If message included, displays the message.
  453.     Otherwise, displays the phrase 'FORTRAN PAUSE'. Execution of the program
  454.     will continue with the press of any key.
  455.  
  456.  
  457.     STOP, CALL EXIT
  458.  
  459.     Use either to close all files, update directory and return control
  460.     to the operating system.
  461.  
  462.     4-4
  463.  
  464.                             IF statements
  465.  
  466.     An IF statement conditionally executes one statement or a block of
  467.     statements.
  468.  
  469.     The IF statement has the form:
  470.  
  471.       IF (exp) stmt
  472.  
  473.     Where exp is a logical or relational expression.
  474.  
  475.  
  476.  
  477.     In a LOGICAL IF statement, we have, as the result of a TEST or
  478.     input/output operation, a condition of true(non-zero) or false(zero). The
  479.     statement, or block of statements, will be executed only if the condition
  480.     is true. In a logical IF, exp simply names the logical variable. In
  481.     addition to the normal variable names, SBM fortran also allows the
  482.     following:
  483.  
  484.                    (EQ), (NE), (ZR), (NZ), (CY), (NC)
  485.  
  486.           or    (EOF),  (NOT.EOF),  (NUMERIC), (NOT.NUMERIC)
  487.  
  488.     stmt can be any non-labled executable statement, but not another IF.
  489.  
  490.  
  491.     The RELATIONAL IF statement performs an on-the-fly comparison of a
  492.     variable to a known value.
  493.  
  494.     Character-strings can be compared, no matter what their length, but only
  495.     for EQ or NE. Other operators may be used, but use with caution. The
  496.     comparison is NOT case sensitive.
  497.  
  498.     The relational IF has the following syntax:
  499.  
  500.           IF (VARIABLE.OP.Constant) stmt
  501.  
  502.     where  OP will be EQ, NE, LT, GT, LE, GE
  503.  
  504.     Constant may be (1) numeric,
  505.                       (2) Ascii character (excluding ';' and '|') , or
  506.                       (3) AsciiZ string.
  507.  
  508.     4-6
  509.  
  510.  
  511.     The block IF conditionally executes blocks of statements. It has the
  512.     following form:
  513.  
  514.     IF (exp) THEN
  515.        block
  516.  
  517.     ELSE
  518.        block
  519.  
  520.     ENDIF
  521.  
  522.     where:
  523.       exp is a logical expression.
  524.  
  525.     THEN must appear on the same line.
  526.  
  527.     block is a series of statements, none of which can be another block-IF.
  528.  
  529.     The ENDIF terminates the block-IF construct.
  530.  
  531.  
  532.  
  533.  
  534.     4-8
  535.  
  536.  
  537.     DO Statement
  538.  
  539.     Here you can specify that a block of statements be executed for a
  540.     specific number of times.
  541.  
  542.  
  543.     Syntax:   DO label index=first,last
  544.  
  545.     where: label is a numeric statement label of a CONTINUE statement which
  546.            is forward from this statement.
  547.  
  548.            index is an integer*2 variable that will be set, and then
  549.            incremented.
  550.  
  551.            first is an integer constant.
  552.  
  553.            last is an integer constant.
  554.  
  555.  
  556.  
  557.  
  558.     CONTINUE statement
  559.  
  560.     Used only in conjunction with the DO statement, this statement is labled
  561.     and is used as the terminator of the block of statements to be executed.
  562.  
  563.  
  564.     Example:  from "testall.for"
  565.  
  566.               do 809 counter=1,10
  567.               write(16,309) counter
  568.           309 format('test output record',i3)
  569.           809 continue
  570.  
  571.  
  572.     6-2
  573.  
  574.     MISCELLANEOUS INTRINSIC FUNCTIONS
  575.  
  576.  
  577.  
  578.  
  579.     PARSE STRING, KEY  [, 'delims']
  580.  
  581.     Given the ascii STRING, isolate the first token. Copy the isolated token
  582.     to KEY and shift STRING left to remove the token KEY. Delimiters are
  583.     blank, comma or equals. Carry is set if no data available to parse (EOR).
  584.  
  585.     You can specify an  additional list of delimiters to be used.
  586.  
  587.     Example:  Consider the string 'now is the-time'
  588.  
  589.         parse string,keword,'(/-+'
  590.  
  591.     After the parse,  keword will be 'now'
  592.                       string will be 'is the-time'
  593.  
  594.                       carry is not set.
  595.  
  596.  
  597.     PARSE_ONLY String, Keword, 'char'
  598.  
  599.     Parse until a specific character is found. We ignore the standard
  600.     delimiters. In fact, the standard delimiters (including blanks) are
  601.     passed to the 'keword' array.
  602.  
  603.     Example:  As above, the string 'now is the-time'
  604.  
  605.         parse_only string, keword,'-'
  606.  
  607.     After the parse,  keword will be 'now is the'
  608.                       string will be 'time'
  609.  
  610.  
  611.  
  612.     LDA           Load address to a register:      LDA VARIABLE, REG
  613.  
  614.  
  615.     UPCASE        Convert a character string to upper case.
  616.  
  617.                   Usage:  UPCASE String
  618.  
  619.  
  620.  
  621.